﻿using System;
using System.Runtime.InteropServices;

namespace Ast.Core.Services.ObjectDefinitions
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
    public struct CmNameControlBlock
    {
        public uint CompressedRefCount;

        public bool Compressed
        {
            get { return (CompressedRefCount & 1) == 0; }
        }

        public uint RefCount
        {
            get { return CompressedRefCount >> 1; }
        }

        public IntPtr NameHash;

        public IntPtr NextHash;

        public ushort NameLength;
    }

    /*
lkd> dt _CM_NAME_CONTROL_BLOCK -v
nt!_CM_NAME_CONTROL_BLOCK
struct _CM_NAME_CONTROL_BLOCK, 7 elements, 0x10 bytes
    +0x000 Compressed       : Bitfield Pos 0, 1 Bit
    +0x000 RefCount         : Bitfield Pos 1, 31 Bits
    +0x004 NameHash         : struct _CM_NAME_HASH, 4 elements, 0xc bytes
    +0x004 ConvKey          : Uint4B
    +0x008 NextHash         : Ptr32 to struct _CM_KEY_HASH, 4 elements, 0x10 bytes
    +0x00c NameLength       : Uint2B
    +0x00e Name             : [1] Wchar
    */
}